Obsidian 使用技巧 - Zirpon | Blog
☀️ 🌃

Obsidian 使用技巧

The quick brown fox jumps over the lazy dog

Posted by Zirpon Cheung on 2024-05-20
Estimated Reading Time 9 Minutes
Words 1.8k In Total
Viewed Times

Obsidian 使用技巧

1. quickadd + cmenu +templater + kanban 插件

学习资料视频:obsidian 无障碍联动效率插件 | 手把手打造高效双链个人知识库 | 全主观分享与推荐 | template | quickadd | cmenu

学习视频内嵌模式

  1. templater 用于设置文章模板
  2. quickadd + cmenu 用于生成 根据模板新建文章 的快捷按钮
  3. kanban 用于根据 任务 - [ ]生成 看板 主要用于日常 todolist
  4. 使用 taskList + checklist 追踪 #check 任务
  5. calendar + daily note 日记
  6. banner 文章顶部背景
  7. Linter + YAML 模板头
  8. admonition 插件 用做 汇总查询 todolist 的背景部件 具体看 diaryTemplate 模板
  9. Tasks插件的查询语法详情请看【效率办公】Obsidain插件之Tasks-任务管理利器

2. Dataview

1. Dataview 查询语法

1
2
3
4
5
6
7
8
9
10
11
12
```dataview
TABLE|LIST|TASK(展现形式) <field> [AS "显示列名"],..., <field> (显示字段)

FROM <source> (like #tag or "folder") (查询地址)

WHERE <expression> (like 'field = value')、contains(tags,"ob/ob插件") (查询条件)

SORT <expression> [ASC/DESC] (like 'field ASC') (排序)

...other data commands (其他命令,如limit,group by等)

```

学习资料:

  1. List 查询
    List查询

  2. Table 查询

  3. Task查询

  4. Calendar 查询

  5. DataView 查询字段及命令

  6. DataView 字段标识

  7. 隐含字段

    dataview能自动的对每个页面添加大量的元数据。

    • file.name: 该文件标题(字符串)。
    • file.folder: 该文件所在的文件夹的路径(字符串)。
    • file.path: 该文件的完整路径(字符串)。
    • file.link: 该文件的一个链接(链接)。
    • file.size: 该文件的大小(bytes)(数字)
    • file.ctime: 该文件的创建日期(日期和时间)。
    • file.cday: 该文件的创建日期(仅日期)。
    • file.mtime: 该文件最后编辑日期(日期和时间)。
    • file.mday: 该文件最后编辑日期(仅日期)。
    • file.tags: 笔记中所有标签组成的数组。子标签按每个级别进行细分,所以#Tag/1/A将会在数组中储存为[#Tag, #Tag/1, #Tag/1/A]
    • file.etags: 笔记中所有显式标签组成的数组;不同于file.tags,不包含子标签。
    • file.outlinks: 该文件所有外链(outgoing link)组成的数组。
    • file.aliases: 笔记中所有别名组成的数组。
      如果文件的标题内有一个日期(格式为yyyy-mm-dd或yyyymmdd),或者有一个Date字段/inline字段,它也有以下属性:
    • file.day: 一个该文件的隐含日期。

2. Dataviewjs API

  1. 原始API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/** A function which maps an array element to some value. */
export type ArrayFunc<T, O> = (elem: T, index: number, arr: T[]) => O;

/** A function which compares two types (plus their indices, if relevant). */
export type ArrayComparator<T> = (a: T, b: T) => number;

/**
* Proxied interface which allows manipulating array-based data. All functions on a data array produce a NEW array
* (i.e., the arrays are immutable).
*/
export interface DataArray<T> {
/** The total number of elements in the array. */
length: number;

/** Filter the data array down to just elements which match the given predicate. */
where(predicate: ArrayFunc<T, boolean>): DataArray<T>;
/** Alias for 'where' for people who want array semantics. */
filter(predicate: ArrayFunc<T, boolean>): DataArray<T>;

/** Map elements in the data array by applying a function to each. */
map<U>(f: ArrayFunc<T, U>): DataArray<U>;
/** Map elements in the data array by applying a function to each, then flatten the results to produce a new array. */
flatMap<U>(f: ArrayFunc<T, U[]>): DataArray<U>;
/** Mutably change each value in the array, returning the same array which you can further chain off of. */
mutate(f: ArrayFunc<T, any>): DataArray<any>;

/** Limit the total number of entries in the array to the given value. */
limit(count: number): DataArray<T>;
/**
* Take a slice of the array. If `start` is undefined, it is assumed to be 0; if `end` is undefined, it is assumbed
* to be the end of the array.
*/
slice(start?: number, end?: number): DataArray<T>;
/** Concatenate the values in this data array with those of another data array. */
concat(other: DataArray<T>): DataArray<T>;

/** Return the first index of the given (optionally starting the search) */
indexOf(element: T, fromIndex?: number): number;
/** Return the first element that satisfies the given predicate. */
find(pred: ArrayFunc<T, boolean>): T | undefined;
/** Find the index of the first element that satisfies the given predicate. Returns -1 if nothing was found. */
findIndex(pred: ArrayFunc<T, boolean>): number;
/** Returns true if the array contains the given element, and false otherwise. */
includes(element: T): boolean;

/**
* Return a sorted array sorted by the given key; an optional comparator can be provided, which will
* be used to compare the keys in leiu of the default dataview comparator.
*/
sort<U>(key: ArrayFunc<T, U>, direction?: 'asc' | 'desc', comparator?: ArrayComparator<U>): DataArray<T>;

/**
* Return an array where elements are grouped by the given key; the resulting array will have objects of the form
* { key: <key value>, rows: DataArray }.
*/
groupBy<U>(key: ArrayFunc<T, U>, comparator?: ArrayComparator<U>): DataArray<{ key: U, rows: DataArray<T> }>;

/**
* Return distinct entries. If a key is provided, then rows with distinct keys are returned.
*/
distinct<U>(key?: ArrayFunc<T, U>, comparator?: ArrayComparator<U>): DataArray<T>;

/** Return true if the predicate is true for all values. */
every(f: ArrayFunc<T, boolean>): boolean;
/** Return true if the predicate is true for at least one value. */
some(f: ArrayFunc<T, boolean>): boolean;
/** Return true if the predicate is FALSE for all values. */
none(f: ArrayFunc<T, boolean>): boolean;

/** Return the first element in the data array. Returns undefined if the array is empty. */
first(): T;
/** Return the last element in the data array. Returns undefined if the array is empty. */
last(): T;

/** Map every element in this data array to the given key, and then flatten it.*/
to(key: string): DataArray<any>;
/**
* Recursively expand the given key, flattening a tree structure based on the key into a flat array. Useful for handling
* heirarchical data like tasks with 'subtasks'.
*/
expand(key: string): DataArray<any>;

/** Run a lambda on each element in the array. */
forEach(f: ArrayFunc<T, void>): void;

/** Convert this to a plain javascript array. */
array(): T[];

/** Allow iterating directly over the array. */
[Symbol.iterator](): Iterator<T>;

/** Map indexes to values. */
[index: number]: any;
/** Automatic flattening of fields. */
[field: string]: any;
}
  1. 代码块参考
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

```dataviewjs
dv.table([], ...)

dv.current()

dv.pages("#books") => all pages with tag 'books'
dv.pages('"folder"') => all pages from folder "folder"
dv.pages("#yes or -#no") => all pages with tag #yes, or which DON'T have tag #no

dv.pagePaths("#books") => the paths of pages with tag 'books'

dv.page("Index") => The page object for /Index
dv.page("books/The Raisin.md") => The page object for /books/The Raisin.md


dv.list([1, 2, 3]) => list of 1, 2, 3
dv.list(dv.pages().file.name) => list of all file names
dv.list(dv.pages().file.link) => list of all file links
dv.list(dv.pages("#book").where(p => p.rating > 7)) => list of all books with rating greater than


// List all tasks from pages marked '#project'
dv.taskList(dv.pages("#project").file.tasks)

// List all *uncompleted* tasks from pages marked #project
dv.taskList(dv.pages("#project").file.tasks
.where(t => !t.completed))

// List all tasks tagged with '#tag' from pages marked #project
dv.taskList(dv.pages("#project").file.tasks
.where(t => t.text.includes("#tag")))

// Render a simple table of book info sorted by rating.
dv.table(["File", "Genre", "Time Read", "Rating"], dv.pages("#book")
.sort(b => b.rating)
.map(b => [b.file.link, b.genre, b["time-read"], b.rating]))

```
  1. 查询例子:
1
2
3
4
5
6
7
8
9
```dataviewjs
for (let group of dv.pages("#book").where(p => p["time-read"].year == 2021).groupBy(p => p.genre)) {
dv.header(3, group.key);
dv.table(["Name", "Time Read", "Rating"],
group.rows
.sort(k => k.rating, 'desc')
.map(k => [k.file.link, k["time-read"], k.rating]))
}
```

3. 配置文件 | PicGo-Core